﻿// Friend Module Table_Module

// Private WithEvents m_DataSet As System.Data.DataSet
// Private WithEvents m_Columns As Dictionary(Of String, Dictionary(Of String, DataTable))

// ' ''' <summary>
// ' ''' 表示数据在内存中的缓存。
// ' ''' </summary>
// ' ''' <value></value>
// ' ''' <returns></returns>
// ' ''' <remarks></remarks>
// 'Public ReadOnly Property DataSet As System.Data.DataSet
// '    Get
// '        If m_DataSet Is Nothing Then
// '            m_DataSet = New System.Data.DataSet
// '            m_DataSet.EnforceConstraints = False
// '        End If
// '        Return m_DataSet
// '    End Get
// 'End Property
// Friend ReadOnly Property Columns(ByVal ConnectionName As String, ByVal LoadTableName As String) As System.Data.DataTable
// Get
// If m_Columns Is Nothing Then
// m_Columns = New Dictionary(Of String, Dictionary(Of String, DataTable))
// End If
// If m_Columns.ContainsKey(ConnectionName) = False Then
// m_Columns.Add(ConnectionName, New Dictionary(Of String, DataTable))
// End If
// Dim zd As Dictionary(Of String, DataTable) = m_Columns.Item(ConnectionName)
// If zd.ContainsKey(LoadTableName) = False Then
// If BI.Data.Connections.Items.ContainsKey(ConnectionName) Then
// Dim Cmd As New BI.Data.SQLCommand(ConnectionName, "Select TOP 1 * From [" & LoadTableName & "]")
// Dim dt As New System.Data.DataTable
// Cmd.FillSchema(dt, SchemaType.Mapped)
// zd.Add(LoadTableName, dt)
// Else
// Throw New Exception("数据源[" & ConnectionName & "]不存在。")
// End If
// End If
// 'If BI.Data.Connections.Items.ContainsKey(ConnectionName) AndAlso m_Columns.Item(ConnectionName).ContainsKey(LoadTableName) = False Then
// '    Dim Cmd As New BI.Data.SQLCommand(ConnectionName, "Select TOP 1 * From [" & LoadTableName & "]")
// '    Dim dt As New System.Data.DataTable
// '    Cmd.FillSchema(dt, SchemaType.Mapped)
// '    m_Columns.Item(ConnectionName).Add(LoadTableName, dt)
// 'End If
// Return m_Columns.Item(ConnectionName).Item(LoadTableName)
// End Get
// End Property

// 'Friend ReadOnly Property ColumnInfo(ByVal ConnectionName As String, ByVal TableName As String) As System.Data.DataTable
// '    Get
// '        If m_ColumnInfo Is Nothing Then
// '            m_ColumnInfo = New Dictionary(Of String, DataTable)
// '        End If
// '        If m_ColumnInfo.ContainsKey(ConnectionName) = False Then
// '            Dim CommandText As String = "SELECT A.TABLE_NAME, A.COLUMN_NAME, A.DATA_TYPE, A.CHARACTER_MAXIMUM_LENGTH, CAST((CASE isnull(B.TABLE_NAME, '') WHEN '' THEN 0 ELSE 1 END) AS bit) " _
// '                                      & "AS PrimaryKey " _
// '                                      & "FROM (SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH " _
// '                                      & "FROM information_schema.columns) AS A LEFT OUTER JOIN " _
// '                                      & "(SELECT TABLE_NAME, COLUMN_NAME " _
// '                                      & "FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE) AS B ON A.COLUMN_NAME = B.COLUMN_NAME AND A.TABLE_NAME = B.TABLE_NAME"
// '            Dim cmd As New SQLCommand(ConnectionName, CommandText)
// '            Dim dt As DataTable = cmd.ExecuteReader
// '            m_ColumnInfo.Add(ConnectionName, dt)
// '        End If
// '        If m_ColumnInfo.ContainsKey(ConnectionName) Then
// '            Return m_ColumnInfo.Item(ConnectionName)
// '        End If
// '        Return Nothing
// '    End Get
// 'End Property
// End Module
// Friend Module Table_Module

// Private WithEvents m_DataSet As System.Data.DataSet
// Private WithEvents m_Columns As Dictionary(Of String, Dictionary(Of String, DataTable))

// ' ''' <summary>
// ' ''' 表示数据在内存中的缓存。
// ' ''' </summary>
// ' ''' <value></value>
// ' ''' <returns></returns>
// ' ''' <remarks></remarks>
// 'Public ReadOnly Property DataSet As System.Data.DataSet
// '    Get
// '        If m_DataSet Is Nothing Then
// '            m_DataSet = New System.Data.DataSet
// '            m_DataSet.EnforceConstraints = False
// '        End If
// '        Return m_DataSet
// '    End Get
// 'End Property
// Friend ReadOnly Property Columns(ByVal ConnectionName As String, ByVal LoadTableName As String) As System.Data.DataTable
// Get
// If m_Columns Is Nothing Then
// m_Columns = New Dictionary(Of String, Dictionary(Of String, DataTable))
// End If
// If m_Columns.ContainsKey(ConnectionName) = False Then
// m_Columns.Add(ConnectionName, New Dictionary(Of String, DataTable))
// End If
// Dim zd As Dictionary(Of String, DataTable) = m_Columns.Item(ConnectionName)
// If zd.ContainsKey(LoadTableName) = False Then
// If BI.Data.Connections.Items.ContainsKey(ConnectionName) Then
// Dim Cmd As New BI.Data.SQLCommand(ConnectionName, "Select TOP 1 * From [" & LoadTableName & "]")
// Dim dt As New System.Data.DataTable
// Cmd.FillSchema(dt, SchemaType.Mapped)
// zd.Add(LoadTableName, dt)
// Else
// Throw New Exception("数据源[" & ConnectionName & "]不存在。")
// End If
// End If
// 'If BI.Data.Connections.Items.ContainsKey(ConnectionName) AndAlso m_Columns.Item(ConnectionName).ContainsKey(LoadTableName) = False Then
// '    Dim Cmd As New BI.Data.SQLCommand(ConnectionName, "Select TOP 1 * From [" & LoadTableName & "]")
// '    Dim dt As New System.Data.DataTable
// '    Cmd.FillSchema(dt, SchemaType.Mapped)
// '    m_Columns.Item(ConnectionName).Add(LoadTableName, dt)
// 'End If
// Return m_Columns.Item(ConnectionName).Item(LoadTableName)
// End Get
// End Property

// 'Friend ReadOnly Property ColumnInfo(ByVal ConnectionName As String, ByVal TableName As String) As System.Data.DataTable
// '    Get
// '        If m_ColumnInfo Is Nothing Then
// '            m_ColumnInfo = New Dictionary(Of String, DataTable)
// '        End If
// '        If m_ColumnInfo.ContainsKey(ConnectionName) = False Then
// '            Dim CommandText As String = "SELECT A.TABLE_NAME, A.COLUMN_NAME, A.DATA_TYPE, A.CHARACTER_MAXIMUM_LENGTH, CAST((CASE isnull(B.TABLE_NAME, '') WHEN '' THEN 0 ELSE 1 END) AS bit) " _
// '                                      & "AS PrimaryKey " _
// '                                      & "FROM (SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH " _
// '                                      & "FROM information_schema.columns) AS A LEFT OUTER JOIN " _
// '                                      & "(SELECT TABLE_NAME, COLUMN_NAME " _
// '                                      & "FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE) AS B ON A.COLUMN_NAME = B.COLUMN_NAME AND A.TABLE_NAME = B.TABLE_NAME"
// '            Dim cmd As New SQLCommand(ConnectionName, CommandText)
// '            Dim dt As DataTable = cmd.ExecuteReader
// '            m_ColumnInfo.Add(ConnectionName, dt)
// '        End If
// '        If m_ColumnInfo.ContainsKey(ConnectionName) Then
// '            Return m_ColumnInfo.Item(ConnectionName)
// '        End If
// '        Return Nothing
// '    End Get
// 'End Property
// End Module
